import $api from '../../api'

export default{
    namespaced:true,
    state:{
        recipe:[],
        newArr:{}
    },
    mutations:{
        getRecipeId(state,payload){
             state.newArr=payload
        }
    },
    actions:{
         async asyncGetAllRecipe(context,payload){
             const res = await $api.recipe.getAllRecipe()
              context.state.recipe=res.data.data
             console.log(res);
         },
         async asyncAddRecipe(context,payload){
             const res = await $api.recipe.addRecipe(payload)
             if(res.data.meta.status){
                 context.dispatch('asyncGetAllRecipe')
             }
         },
         async asyncDelRecipe(context,payload){
             const res = await $api.recipe.delRecipe(payload)
             console.log(res);
             if(res.data.meta.status){
                 context.dispatch('asyncGetAllRecipe')
             }
         },
         async asyncUpDataRecipe(context,payload){
             const res = await $api.recipe.changeRecipe(payload)
             console.log(res);
             if(res.data.meta.status){
                 context.dispatch('asyncGetAllRecipe')
             }
         }

    }
}